import { Mesh, BoxGeometry, MeshPhongMaterial, SphereGeometry, CylinderGeometry } from 'three';

/**
 * 物体工厂类
 * 用于创建各种 Three.js 3D 物体
 */
export default class ObjectFactory {
  /**
   * 创建立方体
   * @param options - 立方体配置选项
   * @param options.width - 宽度，默认为 1
   * @param options.height - 高度，默认为 1
   * @param options.depth - 深度，默认为 1
   * @param options.color - 颜色，默认为白色 0xffffff
   * @param options.position - 位置，默认为 {x: 0, y: 0, z: 0}
   * @returns 创建的立方体网格
   */
  public static createCube({
    width = 1,
    height = 1,
    depth = 1,
    color = 0xffffff,
    position = { x: 0, y: 0, z: 0 }
  } = {}) {
    const geometry = new BoxGeometry(width, height, depth);
    const material = new MeshPhongMaterial({ 
      color,
      shininess: 100,
    });
    const cube = new Mesh(geometry, material);
    cube.position.set(position.x, position.y, position.z);
    return cube;
  }

  /**
   * 创建球体
   * @param options - 球体配置选项
   * @param options.radius - 半径，默认为 1
   * @param options.segments - 分段数，默认为 32
   * @param options.color - 颜色，默认为白色 0xffffff
   * @param options.position - 位置，默认为 {x: 0, y: 0, z: 0}
   * @returns 创建的球体网格
   */
  public static createSphere({
    radius = 1,
    segments = 32,
    color = 0xffffff,
    position = { x: 0, y: 0, z: 0 }
  } = {}) {
    const geometry = new SphereGeometry(radius, segments, segments);
    const material = new MeshPhongMaterial({ 
      color,
      shininess: 100,
    });
    const sphere = new Mesh(geometry, material);
    sphere.position.set(position.x, position.y, position.z);
    return sphere;
  }

  /**
   * 创建圆柱体
   * @param options - 圆柱体配置选项
   * @param options.radiusTop - 顶部半径，默认为 1
   * @param options.radiusBottom - 底部半径，默认为 1
   * @param options.height - 高度，默认为 2
   * @param options.segments - 分段数，默认为 32
   * @param options.color - 颜色，默认为白色 0xffffff
   * @param options.position - 位置，默认为 {x: 0, y: 0, z: 0}
   * @returns 创建的圆柱体网格
   */
  public static createCylinder({
    radiusTop = 1,
    radiusBottom = 1,
    height = 2,
    segments = 32,
    color = 0xffffff,
    position = { x: 0, y: 0, z: 0 }
  } = {}) {
    const geometry = new CylinderGeometry(radiusTop, radiusBottom, height, segments);
    const material = new MeshPhongMaterial({ 
      color,
      shininess: 100,
    });
    const cylinder = new Mesh(geometry, material);
    cylinder.position.set(position.x, position.y, position.z);
    return cylinder;
  }
}
